package com.aaa.service.yy.impl;

import com.aaa.dao.yy.ViewResultSdsDao;
import com.aaa.pojo.yy.ViewResultSds;
import com.aaa.service.yy.ViewResultSdsService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

@Service
public class ViewResultSdsServiceImpl implements ViewResultSdsService {
    @Autowired
    private ViewResultSdsDao resultSdsDao;
    @Override
    public Map<String, Integer> findAll() {
        int normal = 0;
        int mild = 0;
        int moderate = 0;
        int severe = 0;
        List<ViewResultSds> resultSds = resultSdsDao.findAll();
        Iterator iter = resultSds.iterator();
        while (true){
            while(iter.hasNext()) {
                ViewResultSds next = (ViewResultSds) iter.next();
                double forward = next.getForward();
                double inversion = next.getInversion();
                double sum = (forward+inversion)*1.25;
                if (sum<=50.0){
                    ++normal;
                }else if (sum>=50.0 && sum<=59.0){
                    ++mild;
                }else if(sum>= 60.0 && sum<=69.0){
                    ++moderate;

                }else{
                        ++severe;
                    }

            }
            Map<String,Integer> map= new HashMap<>();
            map.put("normal",normal);
            map.put("mild",mild);
            map.put("moderate",moderate);
            map.put("severe",severe);
            return map;
        }

    }

    @Override
    public List<ViewResultSds> findAll1(String page, String limit) {
        int pageInt = Integer.parseInt(page);
        int limitInt = Integer.parseInt(limit);
        int statr = (pageInt - 1) * limitInt;
        List<ViewResultSds> all1 = resultSdsDao.findAll1(statr,limitInt);
        return all1;
    }

    @Override
    public int findCount() {
        return resultSdsDao.findCount();
    }

    @Override
    public ViewResultSds queryResultSdsById(ViewResultSds resultSds) {
        ViewResultSds resultSds1 = resultSdsDao.queryResultSdsById(resultSds);
        return resultSds1;
    }


    @Override
    public int deleteIdList(@Param("idList") List idList) {
        int i = resultSdsDao.deleteIdList(idList);
        return i;
    }

   /* @Override
    public int deleteIdList(List<String> idList) {
        return resultSdsDao.deleteIdList(idList);
    }*/

  /*  @Override
    public int deleteId(int id) {
        int i = resultSdsDao.deleteId(id);
        return i;
    }*/

    @Override
    public List<ViewResultSds> fuzzyFindAll(String name, String testPlanId) {
        return resultSdsDao.fuzzyFindAll(name, testPlanId);
    }
}
